//support.cpp -- use external variable
//compile with external.cpp

//namesp.cpp -- namespaces
#include "namesp_9_11.h"

#include <iostream>
extern double warming;	//using warming from another file 

//function prototypes
void update(double dt);
void local();

using std::cout;
void update(double dt)	//modifies global variable
{
	extern double warming;	//optional redeclaration
	warming += dt;			//uses global warming 
	cout << "Updating global warmiing to " << warming<<" degrees.\n";
	return;
}

void local()			//use local variable
{
	double warming = 0.8;	//new variable hides external one

	cout << "Local warming = " << warming << " degrees.\n";
	//Access global variable with the scope resolution operator
	cout << "But global warming = " << ::warming;
	cout << " degrees.\n";
	return;
}

namespace pers
{
	using std::cout;
	using std::cin;
	void getPerson(Person & rp)
	{
		cout << "Enter first name: ";
		cin >> rp.fname;
		cout << "Enter the last name: ";
		cin >> rp.lname;
	}
	void showPerson(const Person & rp)
	{
		std::cout << rp.lname << "," << rp.fname;
	}
}

namespace debts
{
	void getDebt(Debt & rd)
	{
		getPerson(rd.name);
		std::cout << "Enter debt: ";
		std::cin >> rd.amount;
	}

	void showDebt(const Debt & rd)
	{
		showPerson(rd.name);
		std::cout << ":$" << rd.amount << std::endl;
	}


	double sumDebts(const Debt ar[], int n)
	{
		double total = 0;
		for (int i = 0; i < n; i++)
			total += ar[i].amount;
		return total;
	}
}